package com.konyo.controller;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.konyo.entity.AliyunSmsConf;
import com.konyo.service.AliyunSmsService;
import com.konyo.web.ApiCode;
import com.konyo.web.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/sms")
public class AliyunSmsController {

    @Autowired
    private AliyunSmsService aliyunSmsService;

    /**
     * 发送短信
     * @param aliyunSmsConf
     * @return
     */
    @PostMapping("/sendSms")
    BaseResponse sendSms(@RequestBody AliyunSmsConf aliyunSmsConf){
        SendSmsResponse sendSmsResponse = aliyunSmsService.sendSms(aliyunSmsConf);
        if(sendSmsResponse!=null&&"OK".equals(sendSmsResponse.getCode())){
            return ApiCode.SUCCESS.getBaseResponse();
        }else {
            return ApiCode.FAILED.getBaseResponse();
        }
    }
}
